//
//  FansTableView.m
//  Cat
//
//  Created by lushitong on 2018/12/9.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "FansTableView.h"
#import "HttpUserManager.h"
#import "RelationModel.h"

@interface FansTableView()

@property (nonatomic, strong) NSString *typeString;
@property (nonatomic, strong) NSMutableArray *arrayList;

@end

@implementation FansTableView

- (instancetype)initWithFrame:(CGRect)frame sections:(NSInteger)sections andType:(NSString *)type {
	if (self = [super initWithFrame:frame sections:sections]) {
		self.addRefresh = NO;
		self.needLoadMore = YES;
		self.backgroundColor = [UIColor whiteColor];
		self.tableView.backgroundColor = [UIColor whiteColor];
		self.tableView.showsVerticalScrollIndicator = NO;
		self.noFirstAutoRequest = NO;
		self.outerControlLoading = NO;
        self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, ScreenWidth, 40)];
		self.typeString = type;
	}
	return self;
}

- (void)sendRequest {
	if (self.pageIndex == 1) {
		[self.arrayList removeAllObjects];
	}
	[HttpUserManager getElationListWihIndex:@(self.pageIndex) andType:self.typeString andSuccessInfo:^(RelationModel * _Nonnull model) {
		[self.arrayList addObjectsFromArray:model.list];
		[self p_setupTopCellWithArray:self.arrayList];
		[self finishLoadData:self.arrayList];
	} failure:^(NSInteger code, NSString * _Nonnull message) {
		[FLProgressHUD showError:message];
	}];
	
}

- (void)p_setupTopCellWithArray:(NSArray *)infoArray {
	QKBaseTableCellModel *meTopCellData = [[QKBaseTableCellModel alloc] init];
	meTopCellData.isDynamic = YES;
	meTopCellData.cellClass = @"FanInfoCell";
	meTopCellData.section = 0;
	meTopCellData.cellData = infoArray;
	meTopCellData.cellHeight = kQKFitModule(60);
	[self addTableSectionData:meTopCellData];
}

- (NSMutableArray *)arrayList {
	if (!_arrayList) {
		_arrayList = [[NSMutableArray alloc] init];
	}
	return _arrayList;
}
@end
